package listeners

import (
	"blockchains-aio/util"
	"github.com/gin-gonic/gin"
)

// 20250520
func RegisterPort(router *gin.Engine) {
	router.GET("/port/:number", scanPort)

}

func scanPort(ctx *gin.Context) {
	number := ctx.Param("number")
	if len(number) == 0 {
		ctx.JSON(400, "missing port number parameter")
	}

	if util.TcpScan("localhost", number) {
		ctx.JSON(200, true)
	} else {
		ctx.JSON(200, false)
	}
}
